package com.zwhu.nt;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;


public class case1 {
	 ArrayList<Note> al=new ArrayList();
	 String a="";
	public String read(){
		Note temp= new Note();
		try {
			ObjectInputStream in=new ObjectInputStream(new FileInputStream("note.dat"));
			al=(ArrayList)in.readObject();
			in.close();
		} catch (Exception ex) {
			// TODO: handle exception
		}
		temp=(Note)al.get(0);
		a=temp.getNum();
		System.out.println(a);
		return a;
	}
	
	public void write(){
		try {
			ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("note.dat",false));
			Note nt=new Note();
			nt.setEmail("1");
			nt.setAddress("we");
			nt.setName("ok");
			nt.setNum("1");
			nt.setSex("");
			nt.setTelephone("159878");
			nt.setZip("rt543");
			al.add(nt);
			System.out.println(al.get(0).getNum());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public boolean find(String s){
		boolean b=false;
		Note temp= new Note();
		try {
			ObjectInputStream in=new ObjectInputStream(new FileInputStream("note.dat"));
			al=(ArrayList)in.readObject();
			in.close();
		} catch (Exception ex) {
			System.out.println("sad");
			// TODO: handle exception
		}
		temp=(Note)al.get(0);
		a=temp.getNum();
		System.out.println(a);
		if(s.equals(a))
			b=true;
		return b;
	}
	
	public boolean find2(String s){
		boolean b=false;
		Note temp= new Note();
		try {
			ObjectInputStream in=new ObjectInputStream(new FileInputStream("note.dat"));
			al=(ArrayList)in.readObject();
			in.close();
		} catch (Exception ex) {
			System.out.println("sad");
			// TODO: handle exception
		}
		temp=(Note)al.get(0);
		a=temp.getName();
		System.out.println(a);
		if(s.equals(a))
			b=true;
		return b;
	}
	
	public boolean dele(){
		boolean b=false;
		Note temp= new Note();
		try {
			ObjectInputStream in=new ObjectInputStream(new FileInputStream("note.dat"));
			al=(ArrayList)in.readObject();
			in.close();
		} catch (Exception ex) {
			System.out.println("sad");
			// TODO: handle exception
		}
		System.out.println(al.get(0).getName());
		ArrayList<Note> bl=new ArrayList();
		bl=al;
		System.out.println(bl.get(0).getNum());
		bl.remove(0);
		if(bl==null)
			b=true;
		return b;
	}
	
	public String edit(){
		Note temp= new Note();
		try {
			ObjectInputStream in=new ObjectInputStream(new FileInputStream("note.dat"));
			al=(ArrayList)in.readObject();
			in.close();
		} catch (Exception ex) {
			System.out.println("sad");
			// TODO: handle exception
		}
		System.out.println(al.get(0).getName());
		ArrayList<Note> bl=new ArrayList();
		bl=al;
		System.out.println(bl.get(0).getNum());
		Note nt=new Note();
		nt.setEmail("1");
		nt.setAddress("we");
		nt.setName("ok");
		nt.setNum("1");
		nt.setSex("");
		nt.setTelephone("159878");
		nt.setZip("rt543");
		bl.set(0, nt);
		return bl.get(0).getNum();
	}

}
